/**
 * 所有的界面都继承这里。这里整理统一的操作。
 */
import * as React from "react";
import { Platform, BackHandler } from "react-native";
const NativeListModule = require("../../../core/modules/NativeListModule");

export class BaseComponent<P = {}, S = {}> extends React.Component<P, S> {
  constructor(props: P) {
    super(props);
    //--解决Android物理按键退出应用问题
    if (Platform.OS === "android") {
      BackHandler.addEventListener("hardwareBackPress", this.backPress);
    }
  }

  componentWillUnmount() {
    if (Platform.OS === "android") {
      BackHandler.removeEventListener("hardwareBackPress", this.backPress);
    }
  }

  backPress = () => {
    if (this.props.navigator) {
      this.props.navigator.pop();
      return true;
    } else {
      NativeListModule.finish();
      return true;
    }
  };
}
